<div class="giveHeight"> 
    <table class="responsive dynamicTable display table table-bordered dataTable">
        <thead>        
            <tr>
{# sorting of properties based on query components #}
                    {{ knp_pagination_sortable(pagination, 'N° Facture', 'f.reference') }}
                                {{ knp_pagination_sortable(pagination, 'Raison Social', 'facture.bonLivraisons[0].client') }}
                <th>Departement</th>
                <th>Date</th>
                <th>Heure</th>
                <th>Montant TTc</th>
                <th>Reste</th>
                <th>Reglement</th>
                <th>Action</th>
            </tr>
        </thead>

{# table body #}
{% for facture in pagination %}
        <tr {% if loop.index is odd %}class="color"{% endif %}>
            <td style="width:10%;text-align: center">{{ facture.reference }}</td>
            <td style="width:13%">{{ facture.bonLivraisons[0].client }}</td>
            <td style="width:8%">{{ facture.bonLivraisons[0].departement }}</td>
            <td style="width:6%">{{ facture.date|date('d/m/Y') }} </td>
            <td style="width:4%"> {{ facture.getTime }}</td>
            <td style="width:8%">{{ facture.montantTtc }}</td>
            <td style="width:8%">{{ facture.reste }}</td>
                {% if facture.montantTtc|number_format(3) == facture.reste|number_format(3) %}
                    {% set etat_reglement = 'Non Réglé' %}
                {% elseif facture.reste == 0 %}
                    {% set etat_reglement = 'Réglé' %}
                {% else %}
                    {% set etat_reglement = 'Partiellement Réglé' %}
                {% endif %}
            <td style="width:10%">{{ etat_reglement }}</td>
            <td class="center ">
                <div class="controls center">
                    <a class="tip" href="javascript:showFacture('{{facture.id}}')" title="Visualiser">
                        <span class="icon12 icon-eye-open"></span>
                    </a>
                        {% if facture.canDuplic %}   
                    <a  style="padding-left:5%" class="tip" href="javascript:duppliquerFacture('{{facture.id}}')" title="Duppliquer">
                        <span class="icon12 icomoon-icon-google-plus-2 "></span>
                    </a>                       
                       {% endif %}
                    <a  style="padding-left:5%" class="tip" href="javascript:imprimerFacture('{{facture.id}}')" title="Imprimer">
                        <span class="icon12 icon-print"></span>
                    </a>
                </div>
            </td>
        </tr>
{% endfor %}
    </table>
</div>
<div id="DataTables_Table_0_info" class="dataTables_info">Affichage de {{ (pagination.getCurrentPageNumber -1)*pagination.getItemNumberPerPage + 1}} à {{ (pagination.getCurrentPageNumber -1)*pagination.getItemNumberPerPage + pagination.getItemNumberPerPage}} de {{ pagination.getTotalItemCount }} Facture</div>
{# display navigation #}
<div id="DataTables_Table_0_paginate" class="dataTables_paginate paging_full_numbers">
    {{ knp_pagination_render(pagination) }}
</div>
<script>

    function showFacture(id) {
        lf = remplirlf()
        $.ajax({
            url: '{{path('gds_vente_facture_show')}}',
            data: 'id=' + id,
            success: function(data) {
                $('#div_liste_facture').html(data)
            }
        })
    }
    function editFacture(id) {
        lf = remplirlf()
        $.ajax({
            url: '{{path('gds_vente_facture_edit')}}',
            data: 'id=' + id,
            success: function(data) {
                $('#div_liste_facture').html(data)
            }
        })
    }
    function duppliquerFacture(id) {
        lf = remplirlf()
        $.ajax({
            url: '{{path('gds_vente_facture_duppliquer')}}',
            data: 'id=' + id,
            success: function(data) {
                $('#div_liste_facture').html(data)
            }
        })
    }
    function imprimerFacture(id) {
        $.ajax({
            url: '{{path('gds_vente_bon_facture_saved')}}',
            type: "POST",
            data: 'id='+id,
            success: function(data) {
                $.msgBox({
                    title: "Facture",
                    content: "Impression Effectué avec succés",
                    type: "info",
                    buttons: [{value: "OK"}],
                    success: function(result) {
                        location.reload();
                    }
                });
            }
        })
    }
    function remplirlf() {
        var liste_f = new Array()
        liste_f[0] = $('#filtre_numero').val()
        liste_f[1] = $('#filtre_raison_social').val()
        liste_f[2] = date1
        liste_f[3] = date2
        liste_f[4] = heure1
        liste_f[5] = heure2
        liste_f[6] = $('#filtre_reference').val()
        liste_f[7] = $('#filtre_designation').val()
        liste_f[8] = $('#filtre_ttc1').val()
        liste_f[9] = $('#filtre_ttc2').val()
        liste_f[10] = $('#filtre_type').val()
        return liste_f
    }
</script>{# empty Twig template #}
